package org.feng.config;

import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * mysql 数据库连接配置，需要在Nacos中进行配置信息<br>
 * <pre>
 * dynamic:
 *   mysql:
 *     datasource:
 *       master:
 *         merchantKey: master
 *         host: 127.0.0.1
 *         port: 3306
 *         username: root
 *         password: 123456
 *         database: dynamic_master1
 *         connectTimeout: 30
 *       slave:
 *         merchantKey: slave
 *         host: 127.0.0.1
 *         port: 3306
 *         username: root
 *         password: 123456
 *         database: dynamic_slave1
 *         connectTimeout: 30
 * </pre>
 *
 * @version V1.0
 * @author: fengjinsong
 * @date: 2022年06月15日 14时09分
 */
@Data
@Component
@ConfigurationProperties(prefix = MysqlDatasourceProperties.PREFIX)
public class MysqlDatasourceProperties implements InitializingBean {
    /**
     * 前缀
     */
    public static final String PREFIX = "dynamic.mysql.datasource";

    final List<Property> PROPERTY_LIST = new ArrayList<>();

    /**
     * 主库连接属性
     */
    private Property master;
    /**
     * 其他库连接属性
     */
    private Property slave;

    @Override
    public void afterPropertiesSet() {
        PROPERTY_LIST.add(master);
        PROPERTY_LIST.add(slave);
    }
}
